<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>知识共享成果平台-登录</title>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <link rel="stylesheet" href="login.css">
    <script src="../jquery-3.5.1.js"></script>
</head>
<body>
<div class="layui-container">
    <div class="admin-login-background">
        <div class="layui-form login-form">
            <form class="layui-form" action="">
                <div class="layui-form-item logo-title">
                    <h1>欢迎登录知识成果共享平台</h1>
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-username"></label>
                    <input type="text" name="username" lay-verify="required|account" placeholder="账号" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-password"></label>
                    <input type="password" name="password" lay-verify="required|password" placeholder="密码"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    还没账号，立即<a class="a" href="注册.html">注册</a>
                </div>
                <div class="layui-form-item">
                    <button type="button" class="layui-btn  layui-btn-normal layui-btn-fluid"  onclick="login()"
                            >登 录
                    </button>
                </div>
                <div class="layui-form-item">
                    <button type="button" class="layui-btn  layui-btn-normal layui-btn-fluid"  onclick="login()"
                    >以游客身份登录
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<div>
    <img src="temp.jpg" alt="">
</div>

<script type="text/javascript" src="../layui/layui.js"></script>
<script src="../jquery-3.5.1.js"></script>
<script type="text/javascript">
    function login(){
        var username = document.getElementsByName("username")[0].value;
        var password = document.getElementsByName("password")[0].value;
        var data={
            password:password,
            userId: username
        };
        $.ajax({
            url:'http://106.14.215.182:9091/tby/ipos-login/login',
            // url:'http://localhost:9091/tby/ipos-login/login',
            data:JSON.stringify(data),
            type:"post",
            contentType: 'application/json',
            //返回值类型
            async: false,
            dataType: 'json',
            success:function(result) {
                console.log(result);
                if(result.msg == "SUCCESS"){
                    layui.use('layer',function(){
                        var layer=layui.layer;
                        layer.msg('登录成功！',{
                            icon:1,
                            area:['180px','64px'],
                            time:3000
                        },function () {
                            window.location = 'main.html';
                        });
                    });
                    localStorage.setItem("identity",result.data.identity);
                    localStorage.setItem("name",result.data.name);
                    localStorage.setItem("userId",result.data.userId);
                    if(result.data.token!=null) {
                        localStorage.setItem("token", result.data.token);
                    }
                }else {
                    layui.use('layer',function(){
                        var layer=layui.layer;
                        layer.msg(result.data,{
                            icon:2,
                            area:['180px','64px'],
                            time:3000
                        });
                    });
                }
            },
            error:function(e) {
                console.log(e);
            }
        })
    }
</script>
<script>
    layui.use(['form'],function () {
        var form = layui.form, layer = layui.layer;
        form.render();
    })
</script>
</body>
</html>